package com.captain.special.二叉树.中等;

import com.captain.leetcode.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * Des:
 *
 * @author XL
 * @Date 2022/5/15 11:32
 */
public class 验证二叉搜索树98 {

    long pre = Long.MIN_VALUE;
    boolean flag = false;

    public boolean isValidBST(TreeNode root) {
        recur(root);
        return flag;
    }

    public void recur(TreeNode node) {
        if (node == null) return;
        if (flag) {
            return;
        }
        recur(node.left);
        if (node.val <= pre) {
            flag = true;
        }
        pre = node.val;
        recur(node.right);
    }

}
